<template>
	<view class="" @click.stop="moreIndex = -1">
		<view class="content">
			<view class="grant-staus">
				<view @click="grantClick(item)" class="grant-item" :class="{active:value == item.value}" v-for="(item,index) in grantStaus" :key="index">
					{{item.name}}
					<image v-if="value == item.value" src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/sanjiaoxing.png" mode=""></image>
				</view>
			</view>
			<view class="content-cont">
				<view v-for="(item,index) in list" class="item" :key="index">
					<view class="item-left">
						<view class="left-title text-cut">
							{{item.name}}
						</view>
						<view :style="{color:`${item.status?'red':'#85ce61'}`}" class="left-status">
							{{item.status?'下线':'上线'}}
						</view>
					</view>
					<view class="flex align-center justify-between item-bottom-box">
						<view class="more" @click.stop="moreClick(item,index)">
							更多
							<view class="more-list" v-if="moreIndex == index" >
								<view class="more-item" v-for="(item1,index1) in moreList" :key="index1" @click.stop="moreItemClick(item1,item)">
									{{item1.name}}
								</view>
							</view>
						</view>
						<view class="item-bottom">
							<view class="item-bottom-btn" @click="cancellation(item)" style="background: #FFF4F4;color: #FF2626;">
								删除
							</view>
							<view class="item-bottom-btn" @click="accredit(item)" style="background: #fafafa;color: #000;">
								授权
							</view>
							<view v-if="item.status" class="item-bottom-btn" @click="toPage(`/pagesPet/pages/service/saler/serve/add?id=${item.id}`)">
								编辑
							</view>
						</view>
					</view>
				</view>
				<view class="none">
					没有更多了～
				</view>
			</view>
		</view>
		
		
		<view class="bottom-box-btn" @click="toPage(`/pagesPet/pages/service/saler/serve/add`)">
			<image src="https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/service/add.png" mode=""></image>
			<view class="">
				新增服务
			</view>
		</view>
		
		<!-- v-if="moreIndex == (list.length - 1)" -->
		<view class="" style="height: 250rpx;" >
			
		</view>		
		<showModal ref="showModal"></showModal>
		<use ref="use"></use>		
		<accredit ref="accredit"></accredit>
		<authRecord ref='authRecord'></authRecord> 
	</view>
</template>

<script>
	import {opMyService,addGrantService} from "@/api/pet/service/saler.js"
	import showModal from "@/components/show-modal1"
	import use from "./use.vue"
	import accredit from "./accredit.vue"
	import authRecord from "./authRecord"
	export default {
		components: {
			showModal,
			use,
			accredit,
			authRecord
		},
		props:{
			value:String,
			list:Array
		},
		data(){
			return {
				moreIndex:-2,
				moreList:[],
				grantStaus:[
					{
						name:'已发放',
						value:1
					},
					{
						name:'未发放',
						value:0
					}
				]
			}
		},
		methods:{
			toPage(url){
				uni.navigateTo({
					url
				})
			},
			accredit(item){
				this.$refs.accredit.open({
					item:item,
					success:(data)=>{
						addGrantService(data).then(res=>{
							uni.showToast({
								title:'操作成功',
								icon:'none'
							})
							this.$parent.init()
						})
					}
				})
			},
			moreClick(item,index){
				if(index == this.moreIndex){
					this.moreIndex = -1
					return
				}
				this.moreIndex = index 
				if(item.status){
					this.moreList = [{
						name:'上线',
						type:'up'
					},
					{
						name:'发放',
						type:"grant"
					},
					{
						name:'授权列表',
						type:"record"
					}]
				}else{
					this.moreList = [{
						name:'下线',
						type:'down'
					},
					{
						name:'发放',
						type:"grant"
					},
					{
						name:'授权列表',
						type:"record"
					}]
				}
				console.log(this.moreIndex,index,'1111111')
			},
			moreItemClick(item,data){
				if(item.type == 'record'){
					this.$refs.authRecord.handleOpen({
						item:data,
						type:'my'
					})
				}else if(item.type == 'grant'){
					uni.navigateTo({
						url:`/pagesPet/pages/service/saler/serve/grant?item=${encodeURIComponent(JSON.stringify({
							data:data,
							type:'USER'
						}))}`
					})
				}else if(item.type == 'up' || item.type == 'down'){
					this.$refs.showModal.open({
						content:`确定要${item.type == 'up'?'上线':'下线'}？`,
						success:()=>{
							opMyService({
								opid:data.id,
								field:'status',
								value:item.type == 'up'?0:1
							}).then(res=>{
								uni.showToast({
									title:'操作成功',
									icon:'none'
								})
								this.$parent.init()
							})
						}
					})
				}
			},
			grantClick(item){
				this.$emit('input',item.value)
				this.$parent.init()
			},
			useClick(){
				this.$refs.use.open({
					success:(type)=>{
						
					}
				})
			},
			cancellation(data){
				this.$refs.showModal.open({
					content:"确定要删除？",
					success:()=>{
						opMyService({
							opid:data.id,
							field:'isdel',
							value:1
						}).then(res=>{
							uni.showToast({
								title:'操作成功',
								icon:'none'
							})
							this.$parent.init()
						})
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.bottom-box-btn{
		position: fixed;
		bottom: 160rpx;
		left: 50%;
		transform: translateX(-50%);
		background: var(--primaryBg);
		box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.03);
		border-radius: 40rpx;
		border: 4rpx solid #FFFFFF;
		width: 202rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		image{
			width: 30rpx;
			height: 30rpx;
			margin-right: 12rpx;
		}
		view{
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 28rpx;
			color: var(--h1Color);
			line-height: 40rpx;
			text-align: center;
			font-style: normal;
		}
	}
	.content {
		flex: 1;
		position: relative;
		width: 100%;
		background: #F8F8F8;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		box-sizing: border-box;
	
		top: -28rpx;
	
		.content-cont {
			padding: 16rpx;
		}
	
		.item {
			width: 100%;
			background: #FFFFFF;
			border-radius: 12rpx;
			margin-bottom: 16rpx;
			padding: 22rpx 24rpx;
			box-sizing: border-box;
	
			.item-left {
				flex: 1;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.left-title {
					flex: 1;
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 32rpx;
					color: var(--h1Color);
					line-height: 45rpx;
				}
				.left-status{
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: var(--h1Color);
					line-height: 45rpx;
				}
	
				.left-item {
					width: 100%;
					display: flex;
					align-items: center;
					overflow: hidden;
					margin-bottom: 12rpx;
	
					&:last-child {
						margin-bottom: 0;
					}
	
					view {
						// font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: var(--h2Color);
						line-height: 40rpx;
					}
	
					.left-item-icon {
						margin-right: 12rpx;
						width: 26rpx;
						height: 26rpx;
					}
	
					.left-item-title {
						width: 152rpx;
	
					}
	
					.left-item-value {
						flex: 1;
					}
				}
			}
			.item-bottom-box{
				margin-top: 48rpx;
				.more{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: var(--h3Color);
					line-height: 37rpx;
					text-align: left;
					font-style: normal;
					position: relative;
					.more-list{
						top: 50rpx;
						position: absolute;
						z-index: 99;
						width: 200rpx;
						height: 280rpx;
						padding: 0 25rpx;
						background: #FFFFFF;
						box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.03);
						border-radius: 12rpx;
						border: 1rpx solid #EEEEEE;
						.more-item{
							display: flex;
							align-items: center;
							justify-content: center;
							height: 93rpx;
							border-bottom: 1rpx solid #EEEEEE;
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: var(--h1Color);
							line-height: 37rpx;
							text-align: left;
							font-style: normal;
							&:last-child{
								padding-bottom: 0;
								border-bottom: none;
							}
						}
					}
				}
			}
			.item-bottom {
				display: flex;
				align-items: center;
				justify-content: flex-end;
	
				.item-bottom-btn {
					margin-left: 12rpx;
					width: 142rpx;
					background: var(--primaryBg);
					border-radius: 12rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: var(--btnColor);
					line-height: 64rpx;
					text-align: center;
				}
			}
		}
	
		.none {
			width: 100%;
			text-align: center;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: var(--h4Color);
			line-height: 33rpx;
			margin-top: 40rpx;
		}
	}
	.grant-staus {
		width: 100%;
		height: 108rpx;
		background: #FFFFFF;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		display: flex;
		align-items: center;
		padding: 16rpx 24rpx;
		.grant-item{
			width: 142rpx;
			height: 56rpx;
			background: #F8F8F8;
			border-radius: 28rpx;
			
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: var(--h2Color);
			line-height: 37rpx;
			text-align: center;
			font-style: normal;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 16rpx;
			image{
				position: absolute;
				left: 50%;
				bottom: -10rpx;
				transform: translateX(-50%);
				width: 24rpx;
				height: 12rpx;
			}
			&.active{
				width: 142rpx;
				height: 56rpx;
				color:var(--h1Color);
				background:var(--primaryBg);
				border-radius: 28rpx;
			}
		}
	
	}
	
</style>